<?php
/*
 * @Description    : ExtendMiddleware
 * @Author         : QianLong
 * @Date           : 2023-05-04 10:39:14
 * @LastEditors    : QianLong
 * @Site           : http://www.21ds.cn
 * @LastEditTime   : 2023-10-26 16:50:49
 */
declare(strict_types=1);

namespace App\Middleware\Api;

use Hyperf\HttpServer\Contract\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use App\Constants\Status;
use Psr\Container\ContainerInterface;
use App\Exception\ApiException;

class ExtendMiddleware implements MiddlewareInterface
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * @var RequestInterface
     */
    protected $request;

    public function __construct(ContainerInterface $container, RequestInterface $request)
    {
        $this->container = $container;
        $this->request = $request;
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // header("Access-Control-Allow-Origin: *");
        // header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
        // header('Access-Control-Allow-Headers:T-Token,T-Sign');
        $path = $this->request->path();
        if ($path === '/favicon.ico') {
            unset($path);
            throw new ApiException(Status::INVALID_API);
        }
       return $handler->handle($request);
    }
}
